#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
using namespace std;

class Solution1 {
public:
    bool isalphaornum(char ch)
    {
        return (ch >= '0' && ch <= '9')
            || (ch >= 'a' && ch <= 'z');
    }
    bool isPalindrome(string s)
    {
        for (size_t i = 0; i < s.size(); i++)
        {
            if (s[i] >= 'A' && s[i] <= 'Z')
            {
                s[i] += 32;
            }
        }
        size_t left = 0;
        size_t right = s.size() - 1;
        while (left < right)
        {
            while (left < right && !isalphaornum(s[left]))
            {
                left++;
            }
            while (left < right && !isalphaornum(s[right]))
            {
                right--;
            }
            if (s[left] != s[right])
            {
                return false;
            }
            else
            {
                left++;
                right--;
            }
        }
        return true;
    }
};

class Solution2 {
public:
    void Swap(char* left, char* right)
    {
        char tmp = *left;
        *left = *right;
        *right = tmp;
    }
    void reverse(char* left, char* right)
    {
        while (left < right)
        {
            Swap(left, right);
            left++;
            right--;
        }
    }
    string reverseStr(string s, int k) {
        size_t ret = 2 * k;
        size_t left = 0;

        while (s.size() >= ret)
        {
            reverse(&s[left], &s[left + k - 1]);
            ret += 2 * k;
            left = ret;
        }
        ret -= 2 * k;
        left = ret;
        if (s.size() < k + ret)
        {
            reverse(&s[left], &s[s.size() - 1]);
        }
        else
        {
            reverse(&s[left], &s[left + k - 1]);
        }
        return s;
    }
};


void Test1()
{
    string s;
    getline(cin, s);
    Solution1 so;
    if (so.isPalindrome(s))
    {
        cout << "true" << endl;
    }
    else
    {
        cout << "false" << endl;
    }
}

void Test2()
{
    string s("abcdefhijklmn");
    Solution2 so;
    s = so.reverseStr(s, 5);
    cout << s << endl;
}

void Swap(char& left, char& right)
{
    char tmp = left;
    left = right;
    right = tmp;
}
void reverse(char& left, char& right)
{
    while (left < right)
    {
        Swap(left, right);
        left++;
        right--;
    }
}

void Test3()
{
    string s("hello");
    reverse(s[0], s[3]);
    cout << s;
}

int main()
{
    //Test1();
    Test2();
    //Test3();

	return 0;
}